/* -----------------------------------------------------------------------------
 * PROJECT    : lwf
 * FILE       : AppHitCounter.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * May 11, 2011  mycodetalks			       Created
 */
package net.lwf.service;

import net.lwf.hibernate.dao.AppHitDAO;

/**
 * Class description goes here
 */
public class AppHitCounter {
	
	public static long counter = 0;

	public static long getCounter() {
		if(LwfService.isMock()) {
			return LwfService.getMockCounter();
		}
		else {
			if(counter == 0) {
				counter = new AppHitDAO().getHitCounter();
			}
		}
		return counter;
	}
	
	public static synchronized void increaseCounter() {
		if (!LwfService.isMock()) {
			counter++;
			if (counter % 6 == 0) {
				new AppHitDAO().logHit(counter);
			}

		} else {
			LwfService.incrementHitCounter();
		}
	}
	
/*	private long counter;
	private static AppHitCounter instance;
	
	private AppHitCounter() {
	}
	
	public synchronized static final AppHitCounter getInstance() {
		if(instance == null) {
			instance = new AppHitCounter();
		}
		return instance;
	}

	public long getCounter() {
		if(LwfService.isMock()) {
			return LwfService.getMockCounter();
		}
		if(counter == 0) {
			counter = new AppHitDAO().getHitCounter();
		}
		return counter;
	}
	
	public void increaseCounter() {
		if(!LwfService.isMock()) {
			counter++;
			new AppHitDAO().logHit(counter);
		}
		else {
			LwfService.incrementHitCounter();
		}
	}*/

}



